<template>
<div class="header"
>
<!--折叠图片-->
<div class="collapse-btn">
  <i class="el-icon-menu" @click="collapseChange"></i>

</div>
  <div class="logo">music后台管理</div>
  <div class="header-right">
    <div class="btn-fullscreen" @click="handleFullScreen">
     <el-tooltip :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
      <i class="el-icon-rank"></i>
     </el-tooltip>
    </div>
    <div class="user-avator">
      <img src="../assets/img/user.jpg"/>
    </div>
    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
    <span class="el-dropdown-link">
      {{userName}}
 <i class="el-icon-caret-bottom"></i><!--这是向下的箭头-->
    </span>

      <el-dropdown-menu slot="dropdown"><!--向下拉-->
      <el-dropdown-item command="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</div>
</template>

<script>
import bus from "../assets/js/bus";
export default {
  name: "TheHeader",
  data(){
    return{
      collapse:false,
      fullscreen:false

    }

  },
computed:{//监视主要是状态变化了之后，这里自动的变就行了
  userName(){
    return localStorage.getItem('userName')
  }
},
  methods:{
    collapseChange(){
      this.collapse=!this.collapse;
      bus.$emit('collapse',this.collapse);

    },
    //全屏事件
    handleFullScreen(){
      if(this.fullscreen){
        if(document.exitFullscreen()){
          document.exitFullscreen();
        }else if(document.webkitCanceFullScreen) {//safari Chrome
          document.webkitCanceFullScreen();
        }else if(document.mozCanceFullScreen) { //firefox
          document.mozCanceFullScreen();
        }else if(document.msExitFullScreen) {//ie浏览器
          document.msExitFullScreen();
        }

      }else {
        let element=document.documentElement;
        if(element.requestFullscreen){//从第一个浏览器开始找找不到就往下面找，总有一款适合他
          element.requestFullscreen();
        }else if(element.webkitMatchesSelector){
          element.webkitMatchesSelector();
        }else if(element.mozRequestFullScreen){
          element.mozRequestFullScreen();
        }else if(element.mozRequestFullScreen){
          element.mozRequestFullScreen();
        }

      }
      this.fullscreen=!this.fullscreen;

    },
    handleCommand(command){
      if(command=="logout"){
        localStorage.removeItem('userName');
        this.$router.push("/");
      }
    }


  }
}
</script>

<style scoped>

.header{
  position: relative;
  background-color: #253041;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  color: #ffffff;

}
.collapse-btn{
  float: left;
  padding: 0 21px;
  cursor: pointer;/*鼠标移动过来变成小手*/
  line-height: 70px;
}
.header .logo{

  float: left;
  line-height:70px;
}

.header-right{
  float: right;
  padding-right:50px;/*右边距50*/
  display: flex;/*默认横着布局*/
  height: 70px;
  align-items: center;/*里面内容是居中的*/
}
.btn-fullscreen{
  margin-right: 5px;
  font-size: 24px;
  transform: rotate(45deg);
}
.user-avator{
  margin-left: 20px;
}
.user-avator img{
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.user-name{
  margin-left: 10px;
}
.el-dropdown-link{
  color: #ffffff;
  cursor: pointer;
}
</style>
